<template>
  <div class="pro-card">
    <h2>清单</h2>
    <p v-show="!products.length">
      <i>请添加商品到购物车</i>
    </p>
    <ul>
      <li
        v-for="product in products"
        :key="product.id">
        {{ product.title }} - {{ product.price }} x {{ product.quantity }}
      </li>
    </ul>
    <p>合计： {{ total }}</p>
    <p>
      <el-button
        type="primary" 
        :disabled="!products.length"
        @click="checkout(products)">
        提交
      </el-button>
    </p>
    <p>提交 {{ checkoutStatus }}</p>
  </div>
</template>

<script>
import { mapGetters, mapState, mapActions } from 'vuex'

export default {
  computed: {
    ...mapState({
      checkoutStatus: state => state.cart.checkoutStatus
    }),
    ...mapGetters('cart', {
      products: 'cartProducts',
      total: 'cartTotalPrice',
    }),
  },
  methods: mapActions('cart',[
    'checkout'
  ])
}
</script>

<style lang="stylus">
  .pro-card {
    padding: 30px;
  }
</style>